$(function(){
    $('#alter-btn').click(function(){
        let userid=sessionStorage.getItem('userid');
        let nickname=$('#nickname').val();
        let email=$('#email').val();
        if(userid==null){
            alert('没有登录')
        }else{

            $.ajax({
                url:'http://139.9.177.51:3333/p2p/updateuser',
                type:'post',
                data:{
                    userid:userid,
                    nickname:nickname,
                    email:email
                },
                dataType:'json',
                success:function(res){
                   if(res.code==200){
                       alert('恭喜，修改成功！')
                       localStorage.setItem('username',nickname);
                       location.href='/'
                   }else{
                    alert('不好意思，修改失败！')
                   }
                }
            })
        }
       
    })
})